import { t } from "@/locales";
import { h } from 'vue';
import { Icon } from 'tdesign-icons-vue-next';
import {FormRule, PrimaryTableCol, SelectProps, Space} from "tdesign-vue-next";

/**
 * 搜索表单项
 */
export const searchParams: SearchParamsProps[] = [
    {
        label: t('pages.foodType.title'),
        key: 'title',
    },
];

/**
 * 表格列
 */
export const columns: PrimaryTableCol[] = [
    {
        title: t('pages.foodType.title'),
        ellipsis: true,
        align: 'center',
        colKey: 'title',
    },
    {
        title: t('pages.foodType.icon'),
        ellipsis: true,
        align: 'center',
        colKey: 'icon',
        cell: (h, {row}) => h(Icon, { url: iconfontUrl, name: row.icon, size: '28px' })
    },
    {
        title: t('pages.foodType.remarks'),
        ellipsis: true,
        align: 'center',
        colKey: 'remarks',
    },
];

/**
 * 表单校验规则
 */
export const rules: Record<string, FormRule[]> = {
    icon: [{required: true, message: t('pages.foodType.required.icon'), type: 'error', trigger: 'all'}],
}

/**
 * alibaba矢量图标库json数据
 */
const iconfontArray = {
    "id": "3203735",
    "name": "sport",
    "font_family": "iconfont",
    "css_prefix_text": "icon-",
    "description": "",
    "glyphs": [
        {
            "icon_id": "3859633",
            "name": "运动",
            "font_class": "yundong1",
            "unicode": "e672",
            "unicode_decimal": 58994
        },
        {
            "icon_id": "1079514",
            "name": "运动",
            "font_class": "yundong",
            "unicode": "e63a",
            "unicode_decimal": 58938
        },
        {
            "icon_id": "5150276",
            "name": "收藏",
            "font_class": "shoucang",
            "unicode": "e666",
            "unicode_decimal": 58982
        },
        {
            "icon_id": "11594399",
            "name": "收藏",
            "font_class": "shoucang1",
            "unicode": "e6b3",
            "unicode_decimal": 59059
        },
        {
            "icon_id": "3741670",
            "name": "饮料",
            "font_class": "yinliao",
            "unicode": "e60a",
            "unicode_decimal": 58890
        },
        {
            "icon_id": "3826032",
            "name": "食物",
            "font_class": "shiwu",
            "unicode": "e631",
            "unicode_decimal": 58929
        },
        {
            "icon_id": "5033756",
            "name": "生鲜-肉类3",
            "font_class": "shengxian-roulei",
            "unicode": "e601",
            "unicode_decimal": 58881
        },
        {
            "icon_id": "5158672",
            "name": "蔬菜区",
            "font_class": "shucaiqu",
            "unicode": "e62e",
            "unicode_decimal": 58926
        },
        {
            "icon_id": "5167860",
            "name": "豆类",
            "font_class": "doulei",
            "unicode": "e606",
            "unicode_decimal": 58886
        },
        {
            "icon_id": "5216612",
            "name": "西瓜",
            "font_class": "icon-test",
            "unicode": "e614",
            "unicode_decimal": 58900
        },
        {
            "icon_id": "5218781",
            "name": "零食",
            "font_class": "lingshi",
            "unicode": "e600",
            "unicode_decimal": 58880
        },
        {
            "icon_id": "7777736",
            "name": "坚果",
            "font_class": "jianguo",
            "unicode": "e611",
            "unicode_decimal": 58897
        },
        {
            "icon_id": "14614083",
            "name": "厨房用品-调味瓶",
            "font_class": "chufangyongpin-tiaoweiping",
            "unicode": "e605",
            "unicode_decimal": 58885
        },
        {
            "icon_id": "16985780",
            "name": "其他",
            "font_class": "qita",
            "unicode": "e651",
            "unicode_decimal": 58961
        },
        {
            "icon_id": "17605499",
            "name": "油脂",
            "font_class": "youzhi",
            "unicode": "e819",
            "unicode_decimal": 59417
        },
        {
            "icon_id": "19463537",
            "name": "牛奶 奶瓶",
            "font_class": "niunainaiping",
            "unicode": "e629",
            "unicode_decimal": 58921
        }
    ]
}
export const iconfontUrl = 'https://at.alicdn.com/t/c/font_3203735_yx2meovyrwb.js';

export const iconOptions: SelectProps['options'] = iconfontArray.glyphs.map(i => {
    const value = iconfontArray.css_prefix_text+i.font_class;
    return {
        content: h(Space, {}, [
            h(Icon, { url: iconfontUrl, name: value, size: 'large' }),
            h('span', {}, i.name)
        ]),
        label: i.name,
        value,
    }
});
